#ifndef MULTITHREADSOLVER_H
#define MULTITHREADSOLVER_H

#include <QList>
#include <QObject>
#include "qelapsedtimer.h"
#include "EightQueenSolver.h"

class MultiThreadSolver : public QObject {
  Q_OBJECT
 public:
  MultiThreadSolver(int n);

  void solve();

  // 棋盘大小管理
  int getN() { return m_n; }
  void setN(int n);

  int getResNum() { return resNum; }  // 获取解的个数
  double getTime() { return time; }      // 获取计算时间

  void stopSolve();

  EightQueenSolver::State m_state;
  Board1D lastRes;

 signals:
  void oneResult();
  void finished();
  void stopped();

 private:
  int putQueenAtRow(int* chess, int row);  // 在第row行放皇后

  // 判断一维棋盘chess的第row行第col列能否放皇后
  bool isSafe(int* chess, int row, int col);


  int m_n;     // 皇后数量
  int resNum;  // 解的个数

  // 记录执行时间
  QElapsedTimer mstimer;
  double time;

  QList<Board1D> chessList; // 包含N个一维数组
};

#endif  // MULTITHREADSOLVER_H
